//
//  NotificationCenterManager.m
//  HdStore
//
//  Created by zhenqiu on 16/1/26.
//  Copyright © 2016年 zhenqiu. All rights reserved.
//

#import "NotificationCenterManager.h"
#import "BaseAction.h"




@interface NotificationCenterManager()

-(instancetype)init;

@end

@implementation NotificationCenterManager



// init

-(instancetype)init{
    
    self = [super init];
    
    if (self) {
        // to do
        
        
    }
    
    return self;
}

// get instance
+ (id) getInstance{
   
    
    static dispatch_once_t once ;
    static id instance = nil;

    dispatch_once(&once, ^{
        
        instance = [[NotificationCenterManager alloc] init];
    });
    
    return instance;
}

+(void)sendNotification:(NSString *) key{
    
    
    [[NSNotificationCenter defaultCenter] postNotificationName:key object:nil];
    
}

+ (void)sendNotification:(NSString *)key withUserInfo:(NSDictionary*)userInfo{
    
    [[NSNotificationCenter defaultCenter] postNotificationName:key object:nil userInfo:userInfo];
}

- (void)addDeviceChangeAction:(NSString*) key {
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(exitUserAction:) name:USER_AUTH_FAILED_NOTIFICATION object:nil];
}

-(void)exitUserAction:(NSNotification *) notification{
    
    NSDictionary * userInfo = [notification userInfo];
    NSString *msg = [userInfo valueForKey:NSLocalizedDescriptionKey];
    
//    UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"提示" message:msg delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
//    [alert show];
    [CustomAlertView alertShowTitle:@"提示" message:msg cancelButtonTitle:@"确定" otherButtonTitles:nil block:^(NSInteger buttonIndex) {
        [[CacheHelper getInstance] exit];
        [BaseAction isLoginNav];
    }];
    
    
}

// alert view delegate
//- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex{
//    //  clear cache
//    
//    [[CacheHelper getInstance] exit];
//    [BaseAction isLoginNav];
//}


@end
